export const deepCopy = (obj = {}) => {
  let str,
    newobj = obj.constructor === Array ? [] : {}
  if (typeof obj !== 'object') {
    return
  } else if (JSON) {
    ;(str = JSON.stringify(obj)), //系列化对象
      (newobj = JSON.parse(str)) //还原
  } else {
    for (var i in obj) {
      newobj[i] = typeof obj[i] === 'object' ? deepCopy(obj[i]) : obj[i]
    }
  }
  return newobj
}

export const getUrlParam = function(_url) {
  //定义函数
  if (!_url) {
    return
  }
  let urlformat = _url
  let re = /[^?#&]+\=[^?#&]+/g
  let paramsarr = urlformat.match(re) || []
  let returnjson = {}
  paramsarr.map(data => {
    const splitdata = data.split('=')
    returnjson[splitdata[0]] = splitdata[1]
  })

  return returnjson
}

export const jugdyDate = ({ date1, date2 }) => {
  if (!date2) {
    date2 = new Date().getTime()
  }
  let datesplit
  let timesplit
  let date1Long
  if (/-/.test(date1)) {
    let dateAndTime = date1.split(' ')
    datesplit = dateAndTime[0].split(' ')
    timesplit = dateAndTime[1] && dateAndTime[1].split(' ')
  }
  if (datesplit) {
    if (timesplit) {
      date1Long = new Date(
        datesplit[0],
        datesplit[1],
        datesplit[2],
        timesplit[0],
        timesplit[1],
        timesplit[2]
      ).getTime()
    } else {
      date1Long = new Date(datesplit[0], datesplit[1], datesplit[2]).getTime()
    }
  }
  return date1Long >= date2
}
